# -*- coding: utf-8 -*-
# @Author: qiuchen
# @Date:   2018-03-09 15:16:11
# @Last Modified by:   qiuchen
# @Last Modified time: 2018-03-16 13:36:28
from userManager import tests
import logging 

logger = logging.getLogger('django')

def getAllUser():
	return tests.getAllUser()

def getUserNum():
    return len(tests.getAllUser())

def delUserByAccount(_account):
    tests.delUserByAccount(_account)

def getOneUserByAccount(_account):
    return tests.findUserByAccount(_account)

def userLoginCheck(_useraccount,_userpwd):
    logger.info(_useraccount+" loginAndCheck")
    users = tests.findUserByAccount(_useraccount)
    if(users!=None):
        return (users.user_pwd==_userpwd)
    else:
        logger.info(_useraccount+" has not only one")
        return False

def userCreate(_userFormRequest):
	# _account,_pwd,_email,_photo,_profile
    users = tests.findUserByAccount(_userFormRequest.POST['user_account'])
    if(users==None):
        tests.createUser(_userFormRequest.POST['user_account'],
                    _userFormRequest.POST['user_pwd'],
                    _userFormRequest.POST['user_email'],
                    _userFormRequest.FILES.get('user_avatar','user/avatar/avatar.jpg'),
                    _userFormRequest.POST['user_profile'])
        return True
    else:
        return False
#         files = request.FILES.getlist('file')  
# for f in files:        
#      dest= open('/temp/' + f.name,'wb+')  
#      for chunk in f.chunks():   
#           dest.write(chunk)  
#      dest.close()